<!DOCTYPE html>
<html>
<head>
<include file="Include:meta" />
<title>任务管理-目的地运营集团数据管理平台</title>
<include file="Include:style" />
<style>
	.item-float{ width: 50% !important; }
</style>
</head>
<body>
<include file="Include:header" />
<include file="Include:left" />
<div id="main">
	<div class="crumbs">
		<if condition="$pid neq NULL"><div class="crumbs-text">项目 > [{$project['project_num']}]{$project['project_name']} > 编辑任务</div><else /><div class="crumbs-text">任务管理 > 编辑任务</div></if>
	</div>
	<div id="content">
		<if condition="$pid neq NULL">
		</if>
		<form action="__APP__/Index/task_edit" method="post">
		<input type="hidden" name="action" value="edit">
		<input type="hidden" name="id" value="{$result['id']}">
		<input type="hidden" name="pid" value="{$pid}">
		<div class="form-main">
			<div class="form-title">编辑任务</div>
			<div class="form-item clearfix">
				<div class="input-label"><span class="asterisk">*</span>任务分类</div>
				<div class="input-item">
					<select name="type1" class="form-control classify_select select-add" autocomplete="off">
						<option value="-10" selected>请选择</option>
						<foreach name="type1_list" item="vo">
							<option <if condition="$vo['id'] eq $result['type1']">selected</if> value="{$vo['id']}">{$vo['first_name']}</option>
						</foreach>
					</select>
					<input type="text" name="type1_other" value="{$result['type1_other']}" <if condition="$result['type1'] eq 75">class="form-control w200 ftext ml10"<else />class="form-control w200 ftext ml10 hide"</if> value="" autocomplete="off">
					<span class="error-item">必填项</span>
					<span class="error-item">该分类已存在</span>
				</div>
			</div>
			<div class="form-item clearfix">
				<div class="input-label"><span class="asterisk">*</span>任务子类</div>
				<div class="input-item">
					<select name="type2" class="form-control classify_select select-add" autocomplete="off">
						<option value="-10" selected>请选择</option>
						<foreach name="type2_list" item="vo">
							<option <if condition="$vo['id'] eq $result['type2']">selected</if> value="{$vo['id']}">{$vo['second_name']}</option>
						</foreach>
					</select>
					<input type="text" name="type2_other" value="{$result['type2_other']}" <if condition="$result['type2'] eq 563">class="form-control w200 ftext ml10"<else />class="form-control w200 ftext ml10 hide"</if> value="" autocomplete="off">
					<span class="error-item">必填项</span>
					<span class="error-item">该分类已存在</span>
				</div>
			</div>
			<div class="form-item clearfix">
				<div class="input-label"><span class="asterisk">*</span>任务明细</div>
				<div class="input-item">
					<select name="type3" class="form-control classify_select select-add" autocomplete="off">
						<option value="-10" selected>请选择</option>
						<foreach name="type3_list" item="vo">
							<option <if condition="$vo['id'] eq $result['type3']">selected</if> value="{$vo['id']}">{$vo['third_name']}</option>
						</foreach>
					</select>
					<input type="text" name="type3_other" value="{$result['type3_other']}" <if condition="$result['type3'] eq 161">class="form-control w200 ftext ml10"<else />class="form-control w200 ftext ml10 hide"</if> value="" autocomplete="off">
					<span class="error-item">必填项</span>
					<span class="error-item">该明细已存在</span>
				</div>
			</div>
			<div class="form-item clearfix">
				<div class="item-float">
					<div class="input-label"><span class="asterisk">*</span>任务名称</div>
					<div class="input-item">
						<input type="text" name="name" class="form-control required-text w200" value="{$result['name']}" autocomplete="off">
						<span class="error-item">必填项</span>
					</div>
				</div>
				<div class="item-float">
					<div class="input-label"><span class="asterisk">*</span>任务负责人</div>
					<div class="input-item">
						<select name="head_uid" class="form-control required-selted" style="width:85px;">
							<option value="-10"<if condition="$username eq -10"> selected</if>>姓名</option>
							<foreach name="user_list" item="vo">
							<option value="{$vo['id']}" <if condition="$result['head_uid'] eq $vo['id']">selected</if>>{$vo['username']}</option>
							</foreach>
						</select>
						<span class="error-item">必填项</span>
					</div>
				</div>
			</div>
			<div class="form-item clearfix">
				<div class="item-float">
					<div class="input-label"><span class="asterisk">*</span>开始日期</div>
					<div class="input-item">
						<input type="text" id="d4321" name="start_date" value="{$result['start_date']}" class="form-control Wdate w100 required-text" <literal>onclick="WdatePicker({maxDate:'#F{$dp.$D(\'d4322\')}'})"</literal> readonly autocomplete="off">
						<span class="error-item">必填项</span>
					</div>
				</div>
				<div class="item-float">
					<div class="input-label"><span class="asterisk">*</span>截止日期</div>
					<div class="input-item">
						<input type="text" id="d4322" name="end_date" value="{$result['end_date']}" class="form-control Wdate w100 required-text" <literal>onclick="WdatePicker({minDate:'#F{$dp.$D(\'d4321\',{d:1})}'})"</literal> readonly autocomplete="off">
						<span class="error-item">必填项</span>
					</div>
				</div>
			</div>
			<div class="form-item clearfix">
				<div class="input-label"><span class="asterisk">*</span>任务说明</div>
				<div class="input-item">
					<textarea name="remark" class="form-control w500 h150 required-text" autocomplete="off">{$result['remark']}</textarea>
					<span class="error-item">必填项</span>
				</div>
			</div>
			<div class="editor_cont">
				<div class="form-item">
					<div class="input-label">上传资料</div>
					<div class="input-item">
						<div class="input-group w200 left mr10">
							<input type="text" name="file_name[]" class="form-control file-name" placeholder="请上传相关文档" readonly autocomplete="off">
							<span class="input-group-btn">
								<button class="btn file-submit" type="button">上传</button>
							</span>
						</div>
						<input type="hidden" name="file_url[]" class="file-url" autocomplete="off">
						<span class="error-item">文件名必填</span>
						<a href="javascript:;" class="data-add" data-toggle="tooltip" data-placement="bottom" title="生成"><i class="glyphicon glyphicon-plus"></i></a>
						<span class="error-item">请添加一个文件</span>
						<span class="error-item">请先上传此附件</span>
						<span class="error-item">文件名不能有“,”符号</span>
					</div>
				</div>
				<foreach name="result['file_url']" item="vv" key="vkey">
				<div class="form-item">
					<div class="input-label"></div>
					<div class="input-item">
						<div class="input-group w200 left mr10">
							<input type="text" name="file_name[]" class="form-control file-name" placeholder="请上传相关文档" autocomplete="off" value="{$result['file_name'][$vkey]}">
						</div>
						<input type="hidden" name="file_url[]" class="file-url" autocomplete="off" value="{$vv}">
						<span class="error-item" style="display: none;">文件名必填</span>
						<a href="javascript:;" class="data-delete mr10" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="删除"><i class="glyphicon glyphicon-trash"></i></a>
						<span class="error-item" style="display: none;">请添加一个文件</span>
						<span class="error-item" style="display: none;">请先上传此附件</span>
						<span class="error-item" style="display: none;">文件名不能有“,”符号</span>
					</div>
				</div>
				</foreach>
			</div>
		</div>
		<div class="form-btn-item"><button type="submit" class="btn btn-submit">提交</button><button class="btn btn-default goback" type="button">返回</button></div>
		</form>
	</div>
</div>
<include file="Include:javascript" />
<script type="text/javascript">
$(function(){
	$(".classify_select").on('change',function(){
		$(this).nextAll('.error-item').hide();
		if($(this).find('option:selected').text()=='其它类'){
			$(this).nextAll('input').show();
		}else{
			$(this).nextAll('input').val('').hide();
		}
	});

	//分类
	$("[name='type1']").change(function(){
		var val = $(this).val();
		if(val==-10){
			$("[name='type2']").html("<option value='-10' selected>请先选择任务分类</option>").trigger('change')
		}else{
			$.ajax({
				type:"POST",
				async:false,
				dataType:"json",
				data:{"type1":val,"action":"type2_list"},
				url:"__APP__/Index/task_ajax",
				success:function(data){
					if(data.status){
						var option = "<option value='-10' selected>请选择</option>";
						for(var i=0;i<data.data.length;i++){
							option+="<option value="+data.data[i].id+">"+data.data[i].second_name+"</option>";
						}
						$("[name='type2']").html(option).trigger('change')
					}else{
						$("[name='type2']").html("<option value='-10' selected>请先选择任务分类</option>").trigger('change')
					}
				}
			});
		}
	})

	//子类
	$("[name='type2']").change(function(){
		var val = $("[name='type1']").val(),
			val2 = $(this).val();
		if(val==-10){
			$("[name='type3']").html("<option value='-10' selected>请先选择任务明细</option>").trigger('change')
		}else{
			$.ajax({
				type:"POST",
				async:false,
				dataType:"json",
				data:{"type1":val,"type2":val2,"action":"type3_list"},
				url:"__APP__/Index/task_ajax",
				success:function(data){
					if(data.status){
						var option = "<option value='-10' selected>请选择</option>";
						for(var i=0;i<data.data.length;i++){
							option+="<option value="+data.data[i].id+">"+data.data[i].third_name+"</option>";
						}
						$("[name='type3']").html(option).trigger('change')
					}else{
						$("[name='type3']").html("<option value='-10' selected>请先选择任务明细</option>").trigger('change')
					}
				}
			});
		}
	})

	KindEditor.ready(function(K){
		//上传附件
		var editorFile = K.editor();
		$('.file-submit').on('click',function(){
			var parents = $(this).parents(".input-group");
			editorFile.loadPlugin('insertfile',function(){
				document.cookie="file_name=assist";
				document.cookie="file_type=ppt,pptx,pdf,doc,docx,jpg,jpeg,png,xls,xlsx,txt";
				editorFile.plugin.fileDialog({
					clickFn:function(url,title){
						parents.nextAll(".error-item").hide();
						parents.find(".file-name").val(title).prop("readonly",false);
						parents.nextAll(".file-url").val(url);
						parents.nextAll(".file-delete").show();
						editorFile.hideDialog();
					}
				});
			});
		});
	});
	
	//删除附件
	$(".file-delete").click(function(){
		$(this).hide();
		$(this).nextAll(".error-item").hide();
		$(this).nextAll(".file-url").val("");
		$(this).prevAll(".input-group").find(".file-name").val("").prop("readonly",true);
		$(this).parents("tr").find(".required-text2").next(".error-item").hide();
	});
	//添加资料
	$("body").on("click",".data-add",function(){
		$(this).siblings('.error-item').hide();
		var val = $(this).siblings('.input-group').find('.form-control').val();
		if((val=="" || /^\s+$/.test(val)) && !$(this).prop("readonly")){
			$(this).parent().find('.error-item').eq(2).show();
		}else{
			var tr = $(this).parents(".form-item"),
				cont = $('.editor_cont'),
				html = tr.clone(true);
			
			html.find(".tooltip,.input-group-btn").remove();
			html.find('.input-label').html('');
			tr.find(".error-item,.file-delete").hide();
			html.find(".file-delete").hide();
			tr.find(":text,:hidden").val("");
			tr.find(".file-name").prop("readonly",true);
			html.find(".data-add").replaceWith("<a href='javascript:;' class='data-delete mr10' data-toggle='tooltip' data-placement='bottom' title='删除'><i class='glyphicon glyphicon-trash'></i></a>");
			html.find(".data-delete,.data-add").tooltip({trigger:'hover'});
			cont.append(html);
		}
	});
	//删除资料
	$(document).on("click",".data-delete",function(){
		$(this).parents(".form-item").remove();
	});
	//提交
	$('.btn-submit').click(function(){
		var tag = false;
		$(".required-selted").each(function(){
			var val = $(this).val();
			if(val==-10){
				$(this).nextAll(".error-item").show();
				tag = true;
			}
		})
		$(".required-text").each(function(){
			var val = $(this).val();
			if(val=="" || /^\s+$/.test(val)){
				$(this).nextAll(".error-item").show();
				tag = true;
			}
		});
		$(".select-add").each(function(){
			var $this = $(this),
				val = $this.val(),
				text = $this.nextAll("input").val(),
				txt = $this.find('option:selected').text();
			if(txt=='其它类' && text==""){
				$this.siblings(".error-item").eq(0).show();
				tag = true;
			}else if(val==-10){
				$this.siblings(".error-item").eq(0).show();
				tag = true;
			}else{
				$this.find("option").each(function(){
					if($(this).text()==text){
						$this.siblings(".error-item").eq(1).show()
						tag = true;
					}
				});
			}
		});
		if(tag){
			return false;
		}
	})
	$('.required-text,.ftext').focus(function(){
		$(this).next('.error-item').hide();
	})
	$('.required-selted').change(function(){
		$(this).nextAll('.error-item').hide();
	})
});
</script>
</body>
</html>